if(!jsx3.lang.Class.forName("ux.cdb.admin.system.user.userManage.userWizard.UserOrgSelect")) {
    jsx3.lang.Class.defineClass("ux.cdb.admin.system.user.userManage.userWizard.UserOrgSelect",
            ux.megatron.gui.WizardPanel,
            null,
            function (block) {
                /**
                 * instance initializer
                 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
                 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
                 */
                
        block.prototype.homedir = "ux/cdb/admin/system/user/userWizard/";
        
        block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
                    //call constructor for super class (the super expects the name of the object and the function that it is an instance of)
                    this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
        };
       //block.changeValue=false;
       block.prototype.initialize = function(msg) {
          var me = this;
          this.pageflag=false;  
          this.wizard = this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard");
          var params = ['test'];
          var me = this;
          this.masked = false;
          this.matrix = this.get("mtxOrgSelect");

			this.pageSize = 15;
			this.totalRecordCount = 0;
			this.currentPage = 1;
			this.totalPages = 1; 
			this.pageLoaded = false;
			
			this.pagebar = this.get("blkPageWheel");

  		  var sel_lbl=ux.megatron.Main.getServer().getJSXByName("selOrg2");
          var txt;
          if(this.wizard.Operation=="Edit"){
              //var sel_lbl=ux.megatron.Main.getServer().getJSXByName("selOrg2");
              txt=ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step2@choosed")+"  "+ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.userRelatedOrg;
              this.getOrgList();
          }
          else if(this.wizard.Operation=="Insert"){
              txt=ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@Wizard@UserWizard@SelectUserOrg");
              this.getOrgList();
              var buttonFinish=ux.megatron.Main.getServer().getJSXByName("buttonFinish");
              buttonFinish.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
         }
         sel_lbl.setText(txt,true);
       }
        
        block.prototype.callBackDwr = function(data){
          //alert(data);
        }    

        block.prototype.CheckSelect =  function() {
          //return true;
          var nodes = this.matrix.getSelectedNodes();
          var lbl = this.wizard.get("lblMessage");
          if(nodes.size() >= 1) {
                lbl.setText('',true);
                 var mxorg=this.wizard.get("mtxOrgSelect");
                 var orgName=mxorg.getSelectedNodes().get(0).getAttribute("jsxid");
                 if(this.wizard.Operation=="Insert"){    // when add new user , step2 next is to save to get the sysUserId;
                    //ux.cdb.admin.system.user.UserManage.UserInfoReqUIO["sysUserId"]=0;
                    ux.cdb.admin.system.user.UserManage.UserInfoReqUIO["userRelatedOrg"]=orgName;
					/*
					ux.megatron.util.Dwr.callDwr("UserMgrUCC", "addUserInfo", [ux.cdb.admin.system.user.UserManage.UserInfoReqUIO], this, function(dwrobj){
						if(dwrobj!=null){
							 if(dwrobj.res.flag==1){
								ux.cdb.admin.system.user.UserManage.UserInfoReqUIO["sysUserId"]=dwrobj.content.data[0].sysUserId;
								//console.log(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO["sysUserId"]);
							}else{}
						}
					}, "UserMgrUCC");
					*/
                 }else{
                     if(orgName!=ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.userRelatedOrg){
                          ux.cdb.admin.system.user.UserManage.Orgchanged=true;
                          ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.userRelatedOrg=orgName;
                     }
                 }
              return true;
          } else {
              if(this.wizard.Operation=="Insert"){
                var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@UserOrgSelvalidate");
                lbl.setText(tip,true);
                return false;
              }else{
                  return true;
              }
          }          
        }

         block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
             if(this.CheckSelect()) { 
                 return null; 
             } else {
                return "NONE";
            }
        }

        block.prototype.getOrgList = function() {
               /* @JSC :: begin DEBUG */
               console.log("[getOrgList][start]:");
               console.log(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.systemUserTypeCode);
               /* @JSC :: end */
               ux.megatron.util.Dwr.callDwr("UserMgrUCC", "getOrgListForWizard", 
					[ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.systemUserTypeCode,this.currentPage,this.pageSize], this, this._getOrgListCallback, "UserMgrUCC");
        }
        block.prototype._getOrgListCallback=function(dwrObj){
           /* @JSC :: begin DEBUG */
            console.log("[_getOrgListCallback][start]");
           /* @JSC :: end */
            if(dwrObj!=null){
				this.loadPageControler(dwrObj.content.page.count);
              var cdfDoc = ux.megatron.util.Dwr.toCdfDocument(dwrObj.content.data, "jsxroot", {"id":"jsxid"});
               /* @JSC :: begin DEBUG */
              console.log(cdfDoc);
               /* @JSC :: end */
              this.matrix.setSourceXML(cdfDoc);
              this.matrix.repaint();
              if(this.wizard.Operation=="Edit"){
                  //Todo  
              }
            }
        }

		block.prototype.loadPageControler = function(count) {
			this.totalRecordCount = count;
			this.totalPages = (count%this.pageSize>0) ? (parseInt(count/this.pageSize, 10) + 1) : (count/this.pageSize);
			if(!this.pageLoaded){
				var me = this;
				this.pagebar.initialize();
				this.pagebar.bindWithMatrix(me,me.onPageChange,me.matrix);
				this.pageLoaded = true;
			}
			this.pagebar.setValue(this.currentPage, this.totalPages, this.pageSize, this.totalRecordCount);
		};

		block.prototype.onPageChange = function(msg) {
			this.isQuery = true;
			this.currentPage = msg.currentPageNumber;
			this.getOrgList();
		};

                block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                   if(this.wizard.Operation=="Edit"){
                       this.checkmodify();
                   }
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return null; // return "NONE" to not last status
                }

                block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                     this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                     return null; // return "NONE" to not advance panels
                }

                block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
                    var me = this;
                     var wizard=me.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard");
                    if(!this.getChild(0)) {
                        ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/system/user/userWizard/step2/ui/UserOrgSelectContent.xml", me, me.initialize);
                    }else{
                           //setTimeout(function(){
                              var txt;
                              var sel_lbl=ux.megatron.Main.getServer().getJSXByName("selOrg2");
                              if(wizard.Operation=="Edit"){
                                  txt=ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step2@choosed")+"  "+ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.userRelatedOrg;
                              } else {
                                  txt=ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@Wizard@UserWizard@SelectUserOrg");
                              }
                              sel_lbl.setText(txt,true);
                          // },0);

                    }
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
                    return null; // return "NONE" to not advance panels
                }

                block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                     //var lbl = this.wizard.get("lblMessage");
                     //ux.cdb.admin.system.user.userManage.userWizard.UserInfo.stepCheck(lbl,this);
                             this.checkmodify();
                             /* @JSC :: begin DEBUG */
                             console.log("step2 finish start....");
                             console.log(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO);
                             /* @JSC :: end */
                            if(ux.cdb.admin.system.user.UserManage.Userchanged||ux.cdb.admin.system.user.UserManage.Orgchanged||ux.cdb.admin.system.user.UserManage.Rolechanged){
                               ux.megatron.util.Dwr.callDwr("UserMgrUCC", "updateUserInfo", [ux.cdb.admin.system.user.UserManage.UserInfoReqUIO], this, function(dwrobj){
                                   if(dwrobj!=null){
                                       if(dwrobj.res.flag=="1"){
										   ux.cdb.admin.Cache.remove(ux.cdb.admin.dataautomate.GenericDetail.User+":"+ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.sysUserId);
                                           this.wizard.onClose();
                                           var um=ux.megatron.Main.getServer().getJSXByName("blkWorld");
                                           um.LoadUsers();
                                           return;
                                       }
                                   }
                               }, "UserMgrUCC");
                             //ux.megatron.Dialog.alert();
                           }
                           this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                }
                block.prototype.onStepJump=function(objWIZARD, objSTEP, objEVENT, strCURRENTPANEL){
                     return this.onNext();
                }
                block.prototype.checkmodify=function(){
                     var mxorg=this.wizard.get("mtxOrgSelect");
                     var lbl = this.wizard.get("lblMessage");
                    if(this.wizard.Operation=="Insert"){
                         if(mxorg.getSelectedNodes().size()==0){
                                var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step2@unfinish");
                                lbl.setText(tip,true);
                                return 'NONE';
                           }
                    }
                    if(mxorg.getSelectedNodes().size()>0){
                            var orgName=mxorg.getSelectedNodes().get(0).getAttribute("jsxid");
                            //console.log("orginal value for userRelatedOrg:"+ux.cdb.admin.system.user.UserManage.UserInfoReqUIO["userRelatedOrg"]);
                            ux.cdb.admin.system.user.UserManage.UserInfoReqUIO["userRelatedOrg"]=orgName;
                            //  console.log("now value for userRelatedOrg:"+orgName);
                            ux.cdb.admin.system.user.UserManage.Orgchanged=true;
                    }
                    /* @JSC :: begin DEBUG */
                    console.log("step2 value changed:"+ux.cdb.admin.system.user.UserManage.Orgchanged);
                    /* @JSC :: end */
                    return null;
                }
            }
    );
}
